<template>
  <div>
    <el-dialog class="positionDialog" :title="this.ruleForm.id ? '修改' : '新增'" :visible="showDialog" width="98%"
      :before-close="handleClose" :modal="false" :close-on-click-modal="false">
      <div class="content">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
          <div class="title fir-title">
            <svg-icon class="svg-icon" icon-class="infoAdd" />
            <span>出场过磅</span>
            <!-- <div class="button-box">
              <div @click="setCarTypeIn(0)" :class="carTypeInfo=='0'?'inStoragePCButton2':'inStoragePCButton'">空车写入</div>
              <div @click="setCarTypeIn(1)" :class="carTypeInfo=='1'?'inStoragePCButton2':'inStoragePCButton'">满车写入</div>
            </div> -->
            <div class="button-box">
              <div :style="`background:${this.ruleForm.radio ? 'red' : '#0e7b67'}`" @click="radioClick"
                class="button-boxItem">作为新记录添加</div>
            </div>
          </div>
          <div class="form">
            <el-form-item class="activeClassInput" label="车牌号" prop="carNumber" style="width:500px">
              <el-input class="activeClassInput" v-model="ruleForm.carNumber" placeholder="请输入车牌号"
                :disabled="true"></el-input>
              <el-button class="redAdd" style="border-color:green ;
                  color:green ;" @click="getCarName">刷新</el-button>
              <el-button class="redAdd" style="width:80px"
                @click="handleShowAddDialog('editCarNumber')">更正/录入</el-button>
            </el-form-item>
          </div>
          <div class="title">
            <span>客户信息</span>
          </div>
          <div class="form">
            <el-form-item label="订单号" prop="">
              <el-input v-model="ruleForm.orderNumber" placeholder="请输入订单号" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="客户姓名" prop="clientName">
              <el-select @change="client_nameChange" style="width: 100%;" :disabled="true" v-model="ruleForm.clientName"
                filterable placeholder="请选择客户姓名或输入关键词">
                <el-option v-for="item, index in carList" :key="item.value + index" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="地址" prop="clientAddress">
              <el-input v-model="ruleForm.clientAddress" placeholder="请输入地址" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="ruleForm.phone" placeholder="请输入手机号" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="总量(万斤)" prop="">
              <el-input v-model="ruleForm.contractNumber" placeholder="请输入总量" :disabled="true"></el-input>
            </el-form-item>
          </div>
          <div class="title">
            <span>车辆信息</span>
          </div>
          <div class="form">
            <el-form-item label="司机姓名" prop="driverName">
              <el-select style="width: 100%;" v-model="ruleForm.driverName" filterable placeholder="请选择司机姓名或输入关键词">
                <el-option v-for="item, index in driverInfoLsit" :key="item + index" :label="item.label"
                  :value="item.label">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('driverInfo')">新增</el-button>
            </el-form-item>

          </div>
          <div class="title">
            <span>仓库信息</span>
          </div>
          <div class="form">
            <el-form-item label="种类" :prop="''">
              <el-select style="width: 100%;" v-model="ruleForm.type" filterable placeholder="请选择种类或输入关键词"
                @change="handleChangeCropType">
                <el-option v-for="item, index in cropinfoList" :key="item.label + index" :label="item.label"
                  :value="item.label">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="品种" :prop="''">
              <el-select style="width: 100%;" :disabled="ruleForm.type ? false : true" v-model="ruleForm.variety"
                filterable placeholder="请选择品种或输入关键词">
                <el-option v-for="(item, index) in cropVarietiesList" :key="item + index" :label="item" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="品质" :prop="''">
              <el-select style="width: 100%;" :disabled="ruleForm.type ? false : true" v-model="ruleForm.quality"
                filterable placeholder="请选择品质或输入关键词" @change="handleWarehouse">
                <el-option v-for="(item, index) in cropQualityList" :key="item + index" :label="item" :value="item">
                </el-option>
              </el-select>
              <!-- <el-button class="redAdd" @click="handleShowAddDialog('driverInfo')">新增</el-button> -->
            </el-form-item>
            <el-form-item label="仓号" :prop="''">
              <el-select style="width: 100%;" :disabled="ruleForm.quality ? false : true"
                v-model="ruleForm.warehouseCode" filterable placeholder="请选择仓号或输入关键词" @change="handleDuo">
                <el-option v-for="(item, index) in warehouseList" :key="item.label" :label="item.label"
                  :value="item.label">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="垛号" :prop="''">
              <el-select style="width: 100%;" :disabled="ruleForm.warehouseCode ? false : true"
                v-model="ruleForm.stampCode" filterable placeholder="请选择垛号或输入关键词">
                <el-option v-for="(item, index) in duoList" :key="item + index" :label="item" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="类别" :prop="''">
              <el-select style="width: 100%;" v-model="ruleForm.category" filterable placeholder="请选择类别或输入关键词">
                <el-option v-for="(item, index) in categoryList" :key="item + index" :label="item" :value="item">
                </el-option>
              </el-select>
              <el-button class="redAdd" @click="handleShowAddDialog('CropType')">新增</el-button>
            </el-form-item>
            <el-form-item label="货物规格" prop="">
              <el-select style="width: 100%;" v-model="ruleForm.goodsSpecifications" filterable
                placeholder="请选择货物规格或输入关键词">
                <el-option v-for="(item, index) in specsList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="title">
            <span>过磅信息</span>
            <el-checkbox style="margin-left:50px" @change="radioChange" v-model="ruleForm.radio"><span
                style="font-weight: 900;">做为新记录添加</span></el-checkbox>
          </div>
          <div class="form">
            <el-form-item label="毛重(kg)" prop="">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" class="activeClassInput"
                v-model="ruleForm.totalWeight" placeholder="请输入毛重" disabled></el-input>
              <el-button class="redAdd" style="border-color:green ;
                  color:green ;" @click="getTotalWeight">刷新</el-button>
            </el-form-item>
            <el-form-item label="皮重(kg)" prop="">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" class="activeClassInput"
                v-model="ruleForm.tareWeight" placeholder="请输入皮重" disabled></el-input>
            </el-form-item>
            <el-form-item label="净重(kg)" prop="">
              <el-input v-model="ruleForm.netWeight" placeholder="请输入净重" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="过毛时间" :prop="ruleForm.totalWeight && ruleForm.totalWeight != 0 ? 'hairingTime' : ''">
              <el-date-picker style="width: 100%;" v-model="ruleForm.totalWeighTime" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="请选择过毛时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="过皮时间" :prop="ruleForm.tareWeight ? 'peelingTime' : ''">
              <el-date-picker style="width: 100%;" v-model="ruleForm.tareWeighTime" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="请选择过皮时间">
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="title">
            <span>作物品质</span>
          </div>
          <div class="form">
            <el-form-item label="含水量(%)" :prop="ruleForm.totalWeight && carTypeInfo != '0' ? 'waterContent' : ''">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.waterContent"
                placeholder="请输入含水量(0-100)" :disabled="ruleForm.totalWeight ? false : true"
                @change="shizhongchange('shui')"></el-input>
            </el-form-item>
            <el-form-item label="含油量(%)" prop="">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.oilContent"
                placeholder="当作物为油菜时请输入含油量(0-100)"
                :disabled="(ruleForm.totalWeight && ruleForm.type == '油菜') ? false : true"></el-input>
            </el-form-item>
            <el-form-item label="面筋值(%)" :prop="ruleForm.totalWeight ? '' : ''">
              <el-input oninput="value=value.replace(/[^0-9.]/g,'')" v-model="ruleForm.glutenValue"
                placeholder="当作物为小麦时请输入面筋值(0-100)"
                :disabled="(ruleForm.totalWeight && ruleForm.type == '小麦') ? false : true"></el-input>
            </el-form-item>
          </div>
          <div class="title">
            <span>扣项信息</span>
          </div>
          <div class="form">
            <el-form-item label="袋重(kg)" prop="">
              <el-input v-model="ruleForm.packageWeight" @change="shizhongchange('dai')"
                oninput="value=value.replace(/[^0-9.]/g,'')" placeholder="请输入袋重"></el-input>
            </el-form-item>
            <el-form-item label="扣重(kg)" prop="">
              <el-input v-model="ruleForm.deductWeight" @change="shizhongchange('kou')"
                oninput="value=value.replace(/[^0-9.]/g,'')" placeholder="请输入扣重"></el-input>
            </el-form-item>
            <el-form-item label="实重(kg)" prop="">
              <el-input v-model="ruleForm.actualWeight" disabled oninput="value=value.replace(/[^0-9.]/g,'')"
                placeholder="请输入实重"></el-input>
            </el-form-item>
          </div>
        </el-form>
        <el-dialog width="30%" title="提示" :visible.sync="innerVisible" append-to-body :close-on-click-modal="false">
          <div style="height:100px;text-align: center;">
            您本次过磅重量与上次过磅重量相近，请确认是否关联上次过磅重量
          </div>
          <div class="dialog-footer">
            <el-button class="submit" @click="() => { innerVisible = false; innerVisible2 = false }">确 认</el-button>
            <!-- <el-button class="back" @click="handleClose">返 回</el-button> -->
          </div>
        </el-dialog>
      </div>
      <div class="dialog-footer333">
        <el-button class="submit" @click="handleSubmit">确 认</el-button>
        <el-button class="back" @click="handleClose">返 回</el-button>
      </div>

    </el-dialog>
    <!-- 客户姓名 -->
    <CustomerInfo ref="CustomerInfo" :getKehuList="getKehuList" :showDialog.sync="customerInfo"></CustomerInfo>
    <!-- 新增车牌号 -->
    <CarInfo ref="CarInfo" :showDialog.sync="carInfo"></CarInfo>
    <!-- 司机信息 -->
    <DriverInfo ref="DriverInfo" :showDialog.sync="driverInfo" @handleRefresh="handleRefreshList('driverInfo')">
    </DriverInfo>
    <!-- 作物类别 -->
    <CropType ref="CropType" :showDialog.sync="cropType" @handleRefresh="handleRefreshList('cropType')"></CropType>
    <HandlTable ref="handlTableAdd" :showDialog.sync="dialogVisible" :setTableData='addTableDate'></HandlTable>
  </div>
</template>

<script>
import { Message, MessageBox } from 'element-ui'
import '../scss/style.scss'
import rules from '@/utils/rules'
import { getUserKey } from '@/utils/auth'
import { formatDate } from '@/utils/methods'
import { addVehicleInfo, getCropWeight, getCarLicense, getVehicleInfo, addOrUpdate, getSaleVehicle, getSaleVehicleByCarNumber } from '@/api/table'
import { filterSelect } from '@/utils/methods'
import { refreshWithApi } from '@/api/inStorage'
import { clientTableApi } from '@/api/info'
import { addApi, editApi, warehouseApi, getCropTypeApi, getduoApi, getQualityApi } from '@/api/inCage'
import { selectApi, carinfoApi, driverInfoApi, cropTypeApi, categorySelectApi } from '@/api/select'
import CustomerInfo from '@/views/info/components/CustomerInfo/dialog/AddPopu.vue'
import CarInfo from '@/views/info/components/CarInfo/dialog/AddPopu.vue'
import DriverInfo from '@/views/info/components/DriverInfo/dialog/AddPopu.vue'
import TableCom from '@/components/TableCom'
import CropType from '@/views/info/components/CropType/dialog/AddPopu.vue'
import HandlTable from '../../info/components/Clearing/editCarNumber.vue'
import Cookies from 'js-cookie'
export default {
  props: ['showDialog'],
  components: {
    CarInfo,
    DriverInfo,
    CustomerInfo,
    TableCom,
    HandlTable,
    CropType
  },
  data() {
    return {
      ruleForm: {
        clientName: "",
        carName: '',
        carType: '',
        createUser: '',
        createTime: '',
        phone: "",
        teamCode: '',
        contractNumber: "",
        actualWeight: '',
        carNumber: '',
      },
      ruleForm2: {},
      tableDateObj: {

      },
      rules: rules,
      carList: [],
      carInfo: false,
      driverInfo: false,
      customerInfo: false,
      dialogVisible: false,
      tableHead: [{
        title: '粮食种类',
        prop: 'cropType'
      }, {
        title: '合同量(万斤)',
        prop: 'contractNumber'
      }],
      tableData: [],
      tableOperate: [{
        title: '修改',
        handle: (row) => {
          this.$refs.handlTableAdd.handleGetSelect()
          this.$refs.handlTableAdd.ruleForm = { ...row }
          this.dialogVisible = true
        }
      }],
      delList: [],
      teamCodeList: [],
      farmCodeList: [],
      driverInfoLsit: [],
      carinfoList: [],
      categoryList: [],
      warehouseList: [],
      cropinfoList: [],
      cropVarietiesList: [],
      cropQualityList: [],
      duoList: [],
      specsList: [],
      timeOutFun1: null,
      timeOutFun: null,
      vehicleInfoId: "",
      carTypeInfo: "0",
      tareWeightLsit: [],
      innerVisible2: true,
      innerVisible: false,
      cropType: false,
      farmList: [],
    };
  },
  methods: {
    radioChange() {
      if (this.ruleForm.radio) {
        this.ruleForm2 = this.ruleForm;
        this.ruleForm = {
          ...this.ruleForm,
          driverName: "",
          type: '',
          variety: "",
          quality: "",
          warehouseCode: "",
          stampCode: "",
          category: "",
          goodsSpecifications: "",
          totalWeighTime: "",
          waterContent: "",
          totalWeight: "",
          oilContent: "",
          glutenValue: "",
          packageWeight: "",
          deductWeight: "",
          actualWeight: "",
          id: "",
        }
        // this.ruleForm.radio=!this.ruleForm.radio;
      } else {
        this.ruleForm = { ...this.ruleForm2 }
        this.ruleForm.radio = false;
      }
      this.setAA()
    },
    shizhongchange(type) {
      if (type == 'kou') {
        this.ruleForm = {
          ...this.ruleForm,
          actualWeight: this.ruleForm.netWeight - this.ruleForm.packageWeight - this.ruleForm.deductWeight
        }
      }
      if (type == 'dai') {
        this.ruleForm = {
          ...this.ruleForm,
          actualWeight: this.ruleForm.netWeight - this.ruleForm.packageWeight - this.ruleForm.deductWeight || 0
        }
      }

      // netWeight waterContent packageWeight deductWeight
    },
    setCarTypeIn(num) {
      this.carTypeInfo = num;
      if (num == 0) {

      } else {

      }
    },
    delTable() {
      this.tableData = this.tableData.filter((item) => {
        return !this.delList.includes(item.id)
      })
    },
    radioClick() {
      this.ruleForm.radio = true;
      this.ruleForm2 = this.ruleForm;
      this.ruleForm = {
        ...this.ruleForm,
        driverName: "",
        type: '',
        variety: "",
        quality: "",
        warehouseCode: "",
        stampCode: "",
        category: "",
        goodsSpecifications: "",
        totalWeighTime: "",
        waterContent: "",
        oilContent: "",
        totalWeight: "",
        glutenValue: "",
        packageWeight: "",
        deductWeight: "",
        actualWeight: "",
        id: ''
      }
    },
    addTableDate(data) {
      this.ruleForm.carNumberBak = this.ruleForm.carNumber
      this.ruleForm.carNumber = data;
      this.innerVisible2 = true
      this.ruleForm = {
        ...this.ruleForm,
        driverName: "",
        type: '',
        variety: "",
        quality: "",
        warehouseCode: "",
        stampCode: "",
        category: "",
        goodsSpecifications: "",
        totalWeighTime: "",
        waterContent: "",
        oilContent: "",
        totalWeight: "",
        glutenValue: "",
        packageWeight: "",
        deductWeight: "",
        actualWeight: "",
        id: ''
      }
      this.setAA('cass')
      clearTimeout(this.timeOutFun1)
    },
    client_nameChange(e) {
      const obj = this.carList.filter((item) => { return item.value == e })[0]
      this.ruleForm = {
        ...this.ruleForm,
        client_address: obj.address,
        phone: obj.phone
      }
    },
    // 搜索框时间
    handleFormData() {

    },
    // 选择垛号
    async handleDuo() {
      this.ruleForm.stampCode = ''
      // this.ruleForm.warehouseId = this.warehouseList.find(item => item.value == this.ruleForm.warehouseCode).value
      this.ruleForm.warehouseId = this.warehouseList.filter((item) => { return item.label == this.ruleForm.warehouseCode })[0].value
      if (this.ruleForm.teamCode && this.ruleForm.type && this.ruleForm.quality && this.ruleForm.warehouseCode) {
        const value = this.warehouseList.filter((item) => { return item.label == this.ruleForm.warehouseCode })[0].value
        let res = await getduoApi({ farmCode: this.$farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.type, cropQuality: this.ruleForm.quality, wareId: value })
        this.duoList = res.data
      }
    },
    async handleDuoEdit() {
      const value = this.warehouseList.filter((item) => { return item.label == this.ruleForm.warehouseCode })[0].value
      let res = await getduoApi({ farmCode: this.$farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.type, cropQuality: this.ruleForm.quality, wareId: value })
      this.duoList = res.data
    },
    getKehuList() {
      clientTableApi({ size: 1000, current: 1 }, {}).then(res => {
        this.carList = res.data.records.map((item) => {
          return {
            ...item,
            value: item.clientName,
            label: item.clientName
          }
        })
      })

      selectApi({ type: 'farm_type' }).then((res) => {
        this.farmList = res.data.dictItemList.filter((item) => {
          return item.value == this.$farmCode
        })
      })
      driverInfoApi(this.$farmCode).then((res) => {
        this.driverInfoLsit = res.data
        this.$refs.ruleForm.clearValidate('driverName')
      })
      carinfoApi(this.$farmCode).then((res) => {
        if (res.data && res.data.length) {
          this.carinfoList = res.data
        }

      })
      categorySelectApi().then((res) => {

        if (res.data && res.data.length) {
          this.categoryList = res.data
        }
      })
      selectApi({ type: this.$farmCode }).then((res) => {
        this.teamCodeList = res.data.dictItemList
      })
      getCropTypeApi({ farmCode: this.$farmCode, teamCode: this.$teamCode }).then((res) => {
        if (res.code == 0) {
          this.cropinfoList = res.data
        }
      })
      selectApi({ type: "specs" }).then((res) => {
        this.specsList = res.data.dictItemList
      })

    },
    teamCodeChange(e) {
      this.ruleForm.type = ''
      this.ruleForm.variety = ''
      this.ruleForm.quality = ''
      this.ruleForm.warehouseCode = ''
      this.ruleForm.stampCode = ''
      getCropTypeApi({ farmCode: this.$farmCode, teamCode: this.ruleForm.teamCode }).then((res) => {
        if (res.code == 0) {
          this.cropinfoList = res.data
        }
      })
    },
    teamCodeChangeEdit() {
      getCropTypeApi({ farmCode: this.$farmCode, teamCode: this.ruleForm.teamCode }).then((res) => {
        if (res.code == 0) {
          this.cropinfoList = res.data
        }
      })
    },
    async handleWarehouse() {
      this.ruleForm.warehouseCode = ''
      this.ruleForm.stampCode = ''
      if (this.ruleForm.teamCode && this.ruleForm.type && this.ruleForm.quality) {
        let res = await warehouseApi({ farmCode: this.$farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.type, cropQuality: this.ruleForm.quality })
        if (res.code == 0) {
          this.warehouseList = res.data
        } else {
          this.warehouseList = []
          this.ruleForm.warehouseCode = ''
        }
      }
    },
    // 选择作物品种
    async handleChangeCropType(e) {
      this.ruleForm.variety = ''
      this.ruleForm.quality = ''
      this.ruleForm.warehouseCode = ''
      this.ruleForm.stampCode = ''
      if (!e) return
      Promise.all([
        getQualityApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.type }),
        cropTypeApi(e)
      ]).then(res => {
        this.cropQualityList = res[0].data
        this.cropVarietiesList = res[1].data

      })

    },
    // 选择作物品种
    async handleChangeCropTypeEdit() {
      Promise.all([
        getQualityApi({ farmCode: this.ruleForm.farmCode, teamCode: this.ruleForm.teamCode, cropType: this.ruleForm.type }),
        cropTypeApi(this.ruleForm.type)
      ]).then(res => {
        this.cropQualityList = res[0].data
        this.cropVarietiesList = res[1].data
      })

    },
    handleClose() {
      this.ruleForm = {
        clientName: "",
        carName: '',
        carNumber: "",
        carType: '',
        createUser: '',
        createTime: '',
        phone: "",
        driverName: "",
        teamCode: '',
        contractNumber: ""
      };
      this.$emit('update:showDialog', false)

      clearTimeout(this.timeOutFun)
      clearTimeout(this.timeOutFun1)
      this.$refs.ruleForm.resetFields();
      this.$emit('handlegetCarNumber')
    },
    handleSubmit() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          this.ruleForm = {
            ...this.ruleForm,
            saleId: sessionStorage.getItem("tableInfoViewId")
          }
          //   this.ruleForm.saleId=Cookies.get("tableInfoViewId")
          if (this.ruleForm.totalWeight == 0) {
            addOrUpdate(this.ruleForm).then((res) => {
              clearTimeout(this.timeOutFun)
              this.handleClose();
              this.$emit('handleRefresh')
            })
          } else {
            if (this.ruleForm.radio) {
              clearTimeout(this.timeOutFun)
              addOrUpdate({ ...this.ruleForm, id: "" }).then((res) => {
                this.handleClose();
                this.$emit('handleRefresh')
              })
            } else {
              addOrUpdate(this.ruleForm).then((res) => {
                clearTimeout(this.timeOutFun)
                this.handleClose();
                this.$emit('handleRefresh')
              })
            }

          }




        } else {
          return false;
        }
      });
    },
    // 获取填报人时间
    handleGetInfo() {
      this.ruleForm.createUser = getUserKey() || 'nkjtcyf'
      this.ruleForm.createTime = formatDate(new Date())
    },
    // 新增弹框
    handleShowAddDialog(val) {
      if (val === 'CustomerInfo') {
        this.$refs.CustomerInfo.handleGetInfo()
        this.customerInfo = true
      }
      if (val === 'carInfo') {
        this.$refs.CarInfo.handleGetInfo()
        this.$refs.CarInfo.handleGetSelect()
        this.carInfo = true
      }
      if (val === 'driverInfo') {
        this.$refs.DriverInfo.handleGetInfo()
        this.$refs.DriverInfo.handleGetSelect()
        this.driverInfo = true
      }
      if (val == 'CropType') {
        this.$refs.CropType.handleGetInfo()
        this.cropType = true
      }
      if (val == 'editCarNumber') {
        this.$refs.handlTableAdd.titleText = this.ruleForm.carNumberAA
        this.dialogVisible = true
      }
    },
    handleGW() {
      if (this.ruleForm.totalWeight) {
        this.ruleForm.totalWeight = (this.ruleForm.totalWeight * 1).toFixed(2)
      }
      if (this.ruleForm.tareWeight && this.ruleForm.totalWeight * 1 > this.ruleForm.tareWeight * 1) {
        this.ruleForm.netWeight = (this.ruleForm.totalWeight * 1 - this.ruleForm.tareWeight * 1).toFixed(2)
      } else if (this.ruleForm.tareWeight && this.ruleForm.totalWeight * 1 <= this.ruleForm.tareWeight * 1) {
        Message({
          message: '毛重值应大于皮重值',
          type: 'error',
          duration: 3 * 1000
        })
        this.ruleForm.totalWeight = ''
      }
    },
    // 皮重
    handleTARE() {
      if (this.ruleForm.tareWeight) {
        this.ruleForm.tareWeight = (this.ruleForm.tareWeight * 1).toFixed(2)
      }
      if (this.ruleForm.totalWeight && this.ruleForm.totalWeight * 1 > this.ruleForm.tareWeight * 1) {
        this.ruleForm.netWeight = (this.ruleForm.totalWeight - this.ruleForm.tareWeight).toFixed(2)
      } else if (this.ruleForm.tareWeight && this.ruleForm.totalWeight * 1 <= this.ruleForm.tareWeight * 1) {
        Message({
          message: '毛重值应大于皮重值',
          type: 'error',
          duration: 3 * 1000
        })
        this.ruleForm.tareWeight = ''
      }
    },
    // 单次获取车牌号
    getCarName() {
      MessageBox.confirm('刷新后，将丢失本次车牌号记录，重新获取车牌号', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'cancel',
        type: 'warning'
      }).then(() => {
        refreshWithApi({ carNumber: this.ruleForm.carNumber }).then(res => {
          this.ruleForm.carNumber = res.data.data
          if (res.data.data) {
            this.innerVisible2 = true
            this.setAA('cass')
          }
        })
      })

      // getCarLicense().then((res) => {
      //   this.ruleForm = {
      //     ...this.ruleForm,
      //     carNumber: res.data.data
      //   }
      //   this.innerVisible2 = true
      //   this.setAA('cass')
      // })
    },
    // 单次获取毛重
    getTotalWeight() {
      getCropWeight({farmCode: this.$farmCode,teamCode:this.$teamCode?this.$teamCode:''}).then((res) => {
        this.ruleForm.totalWeight = res.data.data;
        this.ruleForm = {
          ...this.ruleForm,
          totalWeight: res.data.data
        }
      })
    },
    // 连续获取毛重
    getZl() {
      clearTimeout(this.timeOutFun)
      getCropWeight({farmCode: this.$farmCode,teamCode:this.$teamCode?this.$teamCode:''}).then((res) => {
        this.ruleForm.totalWeight = res.data.data;
        this.ruleForm = {
          ...this.ruleForm,
          totalWeight: res.data.data,
          netWeight: res.data.data * 1 - this.ruleForm.tareWeight * 1,
        }
        this.ruleForm.netWeight = res.data.data * 1 - this.ruleForm.tareWeight * 1
        this.timeOutFun = setTimeout(() => {
          this.getZl()
        }, 3000)
      })
    },
    getZl2() {
      clearTimeout(this.timeOutFun)
      getCropWeight({farmCode: this.$farmCode,teamCode:this.$teamCode?this.$teamCode:''}).then((res) => {
        this.ruleForm.tareWeight = res.data.data;
        this.ruleForm = {
          ...this.ruleForm,
          tareWeight: res.data.data
        }
        this.timeOutFun = setTimeout(() => {
          this.getZl2()
        }, 3000)
      })
    },
    setAA(aa) {
      getSaleVehicleByCarNumber({ carNumber: this.ruleForm.carNumber,farmCode:this.$farmCode }).then((ress) => {
        if (ress.data === null) {
          this.ruleForm = {
            ...this.ruleForm,
            totalWeight: '0',
            // netWeight:this.ruleForm.totalWeight,
            // actualWeight:this.ruleForm.totalWeight
            tareWeighTime: formatDate(new Date())
          }
          this.getZl2()
        } else {
          if (this.ruleForm.radio) {
            this.getZl2()
            this.ruleForm = {
              ...this.ruleForm,
              totalWeight: '0',
              // netWeight:this.ruleForm.totalWeight,
              tareWeighTime: formatDate(new Date())
            }
          } else {
            this.getZl()
            if (!this.ruleForm.totalWeight) {
              setTimeout(() => {
                this.mappingRuleForm(ress.data)
              })
            }
            if (aa) {
              setTimeout(() => {
                this.mappingRuleForm(ress.data)
              })
            }
            this.ruleForm = {
              ...this.ruleForm,
              // ...obj,
              netWeight: this.ruleForm.totalWeight * 1 - ress.data.tareWeight * 1,
            };
            setTimeout(() => {
              if (this.innerVisible2 && this.ruleForm.netWeight < 500 && this.ruleForm.totalWeight != 0) {
                this.innerVisible = true
              }
            }, 2000)

          }
          // this.ruleForm={
          //   ...this.ruleForm,
          //   tare:ress.data.gw,
          //   nw:this.ruleForm.gw*1-this.ruleForm.tare*1
          // }
          // this.ruleForm.tare=ress.data.gw
          // this.vehicleInfoId=ress.data.id
          // if(!this.ruleForm.tareWeight){
          //   this.mappingRuleForm(ress.data)
          // }

          // if(this.innerVisible2 &&this.ruleForm.netWeight<500 &&this.ruleForm.tareWeight!=0){
          //   this.innerVisible=true
          // }
        }
      })
    },
    // 连续获取车牌号、皮重列表
    getCarNumber() {
      getCarLicense({farmCode:this.$farmCode,teamCode:this.$teamCode?this.$teamCode:''}).then((res) => {
        if (res.data.data == '') {
          this.timeOutFun1 = setTimeout(() => {
            this.getCarNumber()
          }, 3000)
        } else {
          clearTimeout(this.timeOutFun1)
          this.ruleForm.carNumber = res.data.data
          this.ruleForm.carNumberAA = res.data.data
          this.setAA()
        }



      })

    },
    mappingRuleForm(obj) {
      console.log('this.ruleForm',this.ruleForm);
      console.log('obj',obj);
      this.ruleForm = {
        // ...this.ruleForm,
        ...obj,
        totalWeight: this.ruleForm.totalWeight,
        // tareWeight:obj.tareWeight,
        netWeight: this.ruleForm.netWeight * 1,
        totalWeighTime: formatDate(new Date()),
        // actualWeight:this.ruleForm.totalWeight*1-obj.tareWeight*1,
        tareWeighTime: obj.tareWeighTime
      };
      this.teamCodeChangeEdit()
      if (this.ruleForm.type) {
        this.handleChangeCropTypeEdit()
        if (this.ruleForm.warehouseCode) {
          this.handleDuoEdit()
        }
      }
    },
    async handleRefreshList(val) {
      if (val === 'driverInfo') {
        let res = await driverInfoApi(this.$farmCode)
        this.driverList = res.data
      }
      if (val === 'cropType') {
        let res = await categorySelectApi()
        this.categoryList = res.data
      }
    }
  },
}
</script>

<style lang='scss' scoped>
.form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.el-form-item {
  width: 33%;
  margin-bottom: 0;
}

::v-deep .widthLabel {
  .el-form-item__label {
    width: 160px !important;
  }
}

.content {
  display: flex;
  padding: 0;
}

.fir-title {
  margin-top: 0 !important;
  display: flex;
  line-height: 45px;
}


.button-box {
  border-radius: 5px;
  margin: 0;
  padding: 0;
  margin-left: 1240px;
  line-height: 30px;

  .button-boxItem {
    background: #0e7b67;
    cursor: pointer;
    padding: 0 15px;
    height: 40px;
    line-height: 40px;
    border-radius: 20px;
    color: #fff;
  }
}


::v-deep .el-form-item__content {
  display: flex;
  align-items: center;
  height: 36px;
  line-height: 36px;
}

::v-deep .el-input {
  flex: 1;
  height: 36px;
}

::v-deep .el-select {
  flex: 1;
  height: 36px;
}

::v-deep .el-input__icon {
  line-height: 36px;
}

::v-deep .el-input__inner {
  height: 36px;
}

.activeClassInput {
  ::v-deep .el-input__inner {
    color: rgb(92, 112, 234) !important;
    height: 36px;
    font-weight: 900;
    font-size: 17px;
  }

  ::v-deep .el-input--suffix {
    font-size: 17px;
    color: rgb(92, 112, 234) !important;
    height: 36px;
    font-weight: 900;
  }

  ::v-deep .el-input {
    width: 100%;
  }
}

.title {
  color: #000;
  font-size: 17px !important;
  font-weight: bold;
  // margin-bottom: 0px;
  margin: 0 !important;
}

.dialog-footer333 {
  position: absolute;
  width: 180px;
  left: 50%;
  bottom: 3%;
  transform: translateX(-50%);
}
</style>
